<?php
class X2FlowRecordUpdate extends X2FlowAction {

    public $title = 'Update Record';
    public $info = 'Change one or more fields on an existing record.';

    public function paramRules(){
        return array(
            'title' => Yii::t('studio', $this->title),
            'info' => Yii::t('studio', $this->info),
            'modelReqired' => 1,
            // 'modelClass' => 'modelClass',
            'options' => array(
                array('name' => 'attributes'),
                ));
    }

    public function execute(&$params){
        if(!isset($this->config['attributes']) || empty($this->config['attributes'])) {
            return array (
                false, 
                Yii::t('studio', "Flow item configuration error: No attributes added"));
        }
        $model = $params['model'];

        $this->setModelAttributes($model, $this->config['attributes'], $params);
        if ($model->updateByPk($model->id, $model->attributes)) {
		    if(is_subclass_of($model,'X2Model')) {
                return array (
                    true,
                    Yii::t('studio', 'View updated record: ').$model->getLink ()
                );
            } else {
                return array (true, "");
            }
        } else {
            return array (false, "");
        }
    }

}
